package com.black.security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.black.security.config.DBUserDetailsManager;
import com.black.security.entity.User;
import com.black.security.mapper.UserMapper;
import com.black.security.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;


/**
 * @Author: Young
 * @CreateTime: 2025-08-13
 * @Description: 用户实现类
 * @Version: 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    DBUserDetailsManager dbUserDetailsManager;

    @Resource
    PasswordEncoder passwordEncoder;

    @Override
    public boolean saveUser(User user) {
        UserDetails userDetails = org.springframework.security.core.userdetails.User
                .withUsername(user.getUsername())
                .password(user.getPassword())
                .roles("USER")
                .build();
        dbUserDetailsManager.createUser(userDetails);
        return true;
    }
}
